<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <title>注册</title>
    <link type="text/css" rel="stylesheet" href="/static/css/register.css"/>
    <script type="text/javascript" src="/static/js/jquery-3.4.1.js"></script>
</head>
<body>
<jsp:include page="head.jsp"/>
<div class="popup-r" id="popup">
    <div class="top_nav" id='top_nav'>
        <div align="center">
            <i></i>
            <span>注册账号</span>
        </div>
    </div>

    <div class="min">
        <div class="tc_login">
            <div class="right">
                <form method="get" name="form_login" id="registerFrom">
                    <div>
                        <i class="icon-mobile-phone"></i>
                        <input type="text" name="userName" id="name-r" required="required" placeholder="用户名"
                               autocomplete="off" class="input_yh">
                        <input type="password" name="userPassword" id="pass-r" required="required"
                               placeholder="密码" autocomplete="off" class="input_mm">
                        <input type="password" name="userPassword2" id="qr-pass-r" required="required"
                               placeholder="确认密码" autocomplete="off" class="input_qm">
                        <input type="text" name="code" id="code-r" required="required" placeholder="验证码"
                               autocomplete="off" class="input_co">
                        <dd><img src="captcha" id="code-img-r" alt="看不清楚，换一张"/></dd>
                    </div>
                    <div align="center">
                        <input type="button" onclick="sendAjax()" class="button" title="Sign In" value="注册">
                    </div>
                </form>
            </div>
            <dd>
                <div align="center" class="register"><a href="login" id="register" class="tc">登录</a></div>
            </dd>
        </div>
    </div>
</div>
</body>
<script>
    $('#code-img-r').click(function () {
        $('#code-img-r').attr("src", "captcha?timestamp=" + (new Date()).valueOf());
    });

    function sendAjax() {
        //发送get请求
        $.ajax({
            url: '/register',
            method: 'post',
            data: $('#registerFrom').serialize(),
            dataType: 'json',
            success: function (data) {
                alert(data.info)
                if (data.info == "注册成功") {
                    window.location.href = "/login";
                }
            },
            error: function () {
                alert("请求出错")
            },
            complete: function () {
                $('#code-img-r').attr("src", "captcha?timestamp=" + (new Date()).valueOf());
            }
        })
    }
</script>
</html>
